﻿using System.Windows;
using System.Windows.Controls;

namespace Monti.Controls
{
   /// <summary>
   /// Represents an extended tree control.
   /// </summary>
   public class TreeViewEx : TreeView
   {
      /// <summary>
      /// Initializes a new XTreeView.
      /// </summary>
      public TreeViewEx ()
      {
         this.SelectedItemChanged += SelectionChanged;
      }

      /// <summary>
      /// Dependency property for Selected tree item.
      /// </summary>
      public static readonly DependencyProperty SelectedTreeItemProperty =
         DependencyProperty.Register ("SelectedTreeItem", typeof (object), typeof (TreeViewEx),
         new PropertyMetadata (default (object), SelectedTreeItemChanged));

      /// <summary>
      /// Gets or Sets the selected tree item.
      /// </summary>
      public object SelectedTreeItem
      {
         get { return GetValue (SelectedTreeItemProperty); }
         set { SetValue (SelectedTreeItemProperty, value); }
      }

      /// <summary>
      /// Occurs when the selection changes.
      /// </summary>
      /// <param name="sender"></param>
      /// <param name="e"></param>
      private void SelectionChanged (object sender, RoutedPropertyChangedEventArgs<object> e)
      {
         this.SelectedTreeItem = e.NewValue;
      }

      /// <summary>
      /// Occurs when the selected item changes.
      /// </summary>
      /// <param name="d">DependencyObject</param>
      /// <param name="e">DependencyPropertyChangedEventArgs</param>
      private static void SelectedTreeItemChanged (DependencyObject d, DependencyPropertyChangedEventArgs e)
      {
         // TODO...
      }
   }
}
